home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / ww_tv.exe / TVEDIT1.CPP < prev    next >
C/C++ Source or Header  |  1992-08-24  |  4KB  |  188 lines

  1. /*----------------------------------------------------------*/
  2. /*                                                          */
  3. /*   Turbo Vision 1.0                                       */
  4. /*   Copyright (c) 1991 by Borland International            */
  5. /*                                                          */
  6. /*   Turbo Vision TVEDIT source file                        */
  7. /*----------------------------------------------------------*/
  8.  
  9. #define Uses_TApplication
  10. #define Uses_TEditWindow
  11. #define Uses_TDeskTop
  12. #define Uses_TRect
  13. #define Uses_TEditor
  14. #define Uses_TFileEditor
  15. #define Uses_TFileDialog
  16. #define Uses_TChDirDialog
  17.  
  18. #include <tv.h>
  19.  
  20. #include "tvedit.h"
  21.  
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <strstrea.h>
  25. #include <iomanip.h>
  26.  
  27. TEditWindow *clipWindow;
  28.  
  29. TEditWindow *TEditorApp::openEditor( const char *fileName, Boolean visible )
  30. {
  31.     TRect r = deskTop->getExtent();
  32.     TEditWindow *p = (TEditWindow*)validView( new TEditWindow( r, fileName, wnNoNumber ) );
  33.  
  34.     //??
  35.     p->editor->wordWrap = True;         // ???????????
  36.     p->editor->autosizeMargin = True;   // ???????????
  37.     p->editor->retChar = '\x14';        // ??????????? paragraph symbol
  38.  
  39.     if( !visible )
  40.         p->hide();
  41.     deskTop->insert( p );
  42.     return p;
  43. }
  44.  
  45. TEditorApp::TEditorApp() :
  46.     TProgInit( TEditorApp::initStatusLine,
  47.                TEditorApp::initMenuBar,
  48.                TEditorApp::initDeskTop
  49.              ),
  50.     TApplication()
  51. {
  52.  
  53.     TCommandSet ts;
  54.     ts.enableCmd( cmSave );
  55.     ts.enableCmd( cmSaveAs );
  56.     ts.enableCmd( cmCut );
  57.     ts.enableCmd( cmCopy );
  58.     ts.enableCmd( cmPaste );
  59.     ts.enableCmd( cmClear );
  60.     ts.enableCmd( cmUndo );
  61.     ts.enableCmd( cmFind );
  62.     ts.enableCmd( cmReplace );
  63.     ts.enableCmd( cmSearchAgain );
  64.     disableCommands( ts );
  65.  
  66.     TEditor::editorDialog = doEditDialog;
  67.     clipWindow = openEditor( 0, False );
  68.     if( clipWindow != 0 )
  69.         {
  70.         TEditor::clipboard = clipWindow->editor;
  71.         TEditor::clipboard->canUndo = False;
  72.         }
  73. }
  74.  
  75. void TEditorApp::fileOpen()
  76. {
  77.     char fileName[MAXPATH];
  78.     strcpy( fileName, "*.*" );
  79.  
  80.     if( execDialog( new TFileDialog( "*.*", "Open file",
  81.             "~N~ame", fdOpenButton, 100 ), fileName) != cmCancel )
  82.         openEditor( fileName, True );
  83. }
  84.  
  85. void TEditorApp::fileNew()
  86. {
  87.     openEditor( 0, True );
  88. }
  89.  
  90. void TEditorApp::changeDir()
  91. {
  92.     execDialog( new TChDirDialog( cdNormal, 0 ), 0 );
  93. }
  94.  
  95. void TEditorApp::dosShell()
  96. {
  97.     suspend();
  98.     system("cls");
  99.     cout << "Type EXIT to return...";
  100.     system( getenv( "COMSPEC"));
  101.     resume();
  102.     redraw();
  103. }
  104.  
  105. void TEditorApp::showClip()
  106. {
  107.     clipWindow->select();
  108.     clipWindow->show();
  109. }
  110.  
  111. void TEditorApp::tile()
  112. {
  113.     deskTop->tile( deskTop->getExtent() );
  114. }
  115.  
  116. void TEditorApp::cascade()
  117. {
  118.     deskTop->cascade( deskTop->getExtent() );
  119. }
  120.  
  121. void TEditorApp::handleEvent( TEvent& event )
  122. {
  123.     TApplication::handleEvent( event );
  124.     if( event.what != evCommand )
  125.         return;
  126.     else
  127.         switch( event.message.command )
  128.             {
  129.             case cmOpen:
  130.                 fileOpen();
  131.                 break;
  132.  
  133.             case cmNew:
  134.                 fileNew();
  135.                 break;
  136.  
  137.             case cmChangeDrct:
  138.                 changeDir();
  139.                 break;
  140.  
  141.             case cmDosShell:
  142.                 dosShell();
  143.                 break;
  144.  
  145.             case cmShowClip:
  146.                 showClip();
  147.                 break;
  148.  
  149.             case cmTile:
  150.                 tile();
  151.                 break;
  152.  
  153.             case cmCascade:
  154.                 cascade();
  155.                 break;
  156.  
  157.             default:
  158.                 return ;
  159.             }
  160.     clearEvent( event );
  161. }
  162.  
  163.  
  164.  
  165. int main(int argc, char** argv)
  166. {
  167.     TEditorApp editorApp;
  168.  
  169.     if (argc > 1) {
  170.         TEvent event;
  171.  
  172.         if (stricmp(argv[1], "Play") == 0) {
  173.             event.what = evCommand;
  174.             event.message.command = cmPlay;
  175.             editorApp.putEvent(event);
  176.  
  177.         } else if (stricmp(argv[1], "Record") == 0) {
  178.             event.what = evCommand;
  179.             event.message.command = cmRecord;
  180.             editorApp.putEvent(event);
  181.         }
  182.     }
  183.  
  184.     editorApp.run();
  185.     return 0;
  186. }
  187.  
  188.